/**
 * 取选选中文本的当前段落
 * ruirui
 * @param editor 
 * @param contextLength 
 * @returns 
 */
import { JsonToMarkdown } from "@/utils/JsonToMarkDown";

export function getSelectionWithCurrentParagraph(editor:any) {
  const { state } = editor;
  const {to,from, $from } = state.selection;

  // 获取当前段落范围
  const paragraphStart = $from.start($from.depth);
  const paragraphEnd = paragraphStart + $from.parent.nodeSize-2;

  // 获取当前段落完整内容
  const currentParagraph = state.doc.textBetween(paragraphStart, paragraphEnd, " ");

  return {
    currentParagraph: currentParagraph.trim(),
    // 如果需要也可以返回选中文本
    selectedText: state.doc.textBetween(from,to, " "),
    from:from,
    to:to
  };
}